<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="top">
        <span class="lar" id="bgc"></span>
        <span class="lar" id="login" onclick="toLogin()">登录</span>
        <span class="lar" id="register" onclick="toRegister()">注册</span>
    </div>
    <div id="main">
        <span class="mianWord">账号:<input type="text" id="account"></span>
        <span class="mianWord">密码:<input type="password" id="password"></span>
        <span id="mainButton">
            <button id="_mClear" onclick="_mClear()">重置</button>
            <button id="_mLogin" onclick="_mLogin()">登录</button>
        </span>
    </div>
</body>
</html>
<style>
    body{
        background-color: #e0edf7;
    }
    #top{
        position: absolute;
        top: 100px;
        left: calc(50% - 75px);
        height: 40px;
        width: 150px;
        background-color: #fff;
        border: 1px solid #e0edf7;
        border-radius: 20px;
    }
    .lar{
        display: inline-block;
        position: absolute;
        height: 32px;
        width: 70px;
        line-height: 32px;
        text-align: center;
        font-size: 18px;
        font-weight: 500;
        cursor: pointer;
    }
    #bgc{
        top: 3px;
        left: 3px;
        background-color: #598bf0;
        border: 1px solid #fff;
        border-radius: 20px;
    }
    #login{
        top: 3px;
        left: 3px;
    }
    #register{
        top: 3px;
        right: 3px;
    }
    @keyframes lr {
        from{left: 3px;}
        to{left: 76px;}
    }
    @keyframes rl {
        from{left: 76px;}
        to{left: 3px;}
    }

    #main{
        position: absolute;
        top: 142px;
        left: calc(50% - 200px);
        height: 200px;
        width: 400px;
        background-color: #fff;
    }
    .mianWord{
        position: relative;
        display: inline-block;
        font-size: 18px;
        font-weight: 500;
        color: gainsboro;
        left: calc((50% - 13.1px)/2);
        top: 30px;
        margin-top: 15px;
    }
    #mainButton{
        position: absolute;
        bottom: 25px;
        right: 40px;
    }
    #mainButton button{
        cursor: pointer;
        background-color: rgb(213, 183, 241);
        border: 1px solid white;
        border-radius: 3px;
        font-size: 16px;
        height: 30px;
    }
    @keyframes _mianRotate {
        from{transform: rotateY(0deg);}
        to{transform: rotateY(360deg);}
    }
</style>
<script>
    var now = '_nowLogin'
    let bgc = document.getElementById('bgc');
    let _main = document.getElementById('main');
    let loginButton = document.getElementById('_mLogin');
    let _account = document.getElementById('account');
    let _password = document.getElementById('password');
    function toRegister(){
         _account.value = '';
        _password.value = '';
        if(now === '_nowLogin'){
            bgc.style.animation = 'lr 2s';
            bgc.style.animationFillMode = 'forwards';
            _main.style.animation = '_mianRotate 2s';
            setTimeout(() =>{
                loginButton.innerText = '注册'
            },1000)
            setTimeout(() =>{
                _main.style = 'none'
                //void _main.offsetWidth
            },2100)
            now = '_nowregister';
        }
        
    }
    function toLogin(){
        _account.value = '';
        _password.value = '';
        if(now === '_nowregister'){
            bgc.style.animation = 'rl 2s';
            bgc.style.animationFillMode = 'forwards';
            _main.style.animation = '_mianRotate 2s';
            setTimeout(() => {
                loginButton.innerText = '登录'
            }, 1000)
            setTimeout(() => {
                _main.style = 'none'
                //void _main.offsetWidth
            }, 2100)
            now = '_nowLogin';
        }
    }
    function _mClear(){
        _account.value = '';
        _password.value = '';
    }
    function _mLogin(){
        if(_account.value.trim() == '' || _password.value.trim() == ''){
            alert('输入错误')
        } else{
            if(now === '_nowLogin'){
                alert('登录成功')
            } else {
                alert('注册成功')
            }
        }
    }
</script>